home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / Gfx4PCQ.lha / WindowLib / Examples / Liss / Liss.p < prev    next >
Encoding:
Text File  |  1997-02-09  |  3.2 KB  |  111 lines

  1. PROGRAM Liss;
  2. {This program draws so called Lissajous figures you get if you superpose
  3.  the movement of two independent pendulums. 
  4.  The parameters of these pendulums can be setup by the sliders on the screen.
  5.  Another fine demonstration program for THOR's windowlib.
  6.  © 1997 THOR Software}
  7.  
  8. {Include windowlib, and strings.}
  9. {$I "include:utils/windowlib.i"}    
  10. {$I "include:utils/stringlib.i"}
  11.     
  12.  
  13. VAR
  14.     window        :    WindowPtr;
  15.     gadn,gadm    :    GadgetPtr;
  16.     gaddelta    :    GadgetPtr;
  17.     msg        :    INTEGER;
  18.     
  19.  
  20. {this program draws the figure, giving the two frequencies and the
  21.  phase delta between them}
  22. PROCEDURE DrawFigure(n,m : INTEGER; delta : REAL);
  23. VAR    i    :    INTEGER;
  24. VAR    x,y    :    REAL;
  25. VAR    fac    :    REAL;
  26. VAR    connect    :    BOOLEAN;
  27.  
  28. BEGIN
  29.     connect:=FALSE;
  30.     fac:=3.141592654/180;
  31.     
  32.     FOR i:=0 TO 360 DO BEGIN
  33.         x:=200.0*cos(i*n*fac)+320.0;
  34.         y:=100.0*sin((i+delta)*m*fac)+120.0;
  35.         IF NOT connect THEN
  36.             Plot(window,x,y)    {either plot the starting point}
  37.         ELSE
  38.             DrawTo(window,x,y);    {or draw a line to the last point}
  39.         connect:=TRUE;
  40.     END;
  41.     
  42. END;
  43.  
  44. {draw an integer value to the screen}
  45. PROCEDURE PrintInt(w : WindowPtr;x,y : INTEGER;value : INTEGER);
  46. VAR
  47.     buf    :    ARRAY [0..15] OF CHAR;
  48.     dummy    :    INTEGER;
  49.     
  50. BEGIN
  51.     dummy:=IntToStr(@buf,value);    {convert the integer to a string}
  52.     Position(window,x,y);        {setup position where to plot the text}
  53.     DrawText(window,@buf);        {draw the ASCII version of the number}
  54. END;
  55.  
  56. {the main program}
  57. BEGIN
  58.     InitGraphics;    {setup gfx system}
  59.     
  60.     {open a window on the WB screen}
  61.     window:=OpenScreenWindow(NIL,0,0,640,240,2+4+8,"Lissajous figures");
  62.     Color(window,1);    {choose color}
  63.  
  64.     {now create two sliders. The arguments are x and y position
  65.       width and height and a flag beeing FALSE for horizontal freedom
  66.      or TRUE for vertical freedom.}
  67.     gadn:=CreateSlider(window,4,10,100,8,FALSE);
  68.     gadm:=CreateSlider(window,4,30,100,8,FALSE);
  69.     gaddelta:=CreateSlider(window,4,50,100,8,FALSE);
  70.  
  71.     {Setup the values for the sliders. They are number of items in a list,
  72.      number of items visible at once (here one) and the actual position
  73.      in a list}
  74.     SetSlider(gadn,10,1,0);
  75.     SetSlider(gadm,10,1,0);
  76.     SetSlider(gaddelta,180,1,0);
  77.     
  78.     {tell windowlib we want to receive if the user either want to
  79.      shut down or releases one of our sliders}
  80.     RequestStart(window,CLOSEWINDOW_f OR GADGETUP_f);
  81.     REPEAT
  82.         ClearWindow(window);    {clear window}
  83.         RefreshButton(gadn);    {redraw sliders}
  84.         RefreshButton(gadm);
  85.         RefreshButton(gaddelta);
  86.         
  87.         {reprint the position of the sliders}                
  88.         PrintInt(window,110,16,FirstFromSlider(gadn)+1);
  89.         PrintInt(window,110,36,FirstFromSlider(gadm)+1);
  90.         PrintInt(window,110,56,FirstFromSlider(gaddelta));
  91.     
  92.         {draw the figure, reading the current position of the
  93.          sliders}
  94.         DrawFigure(FirstFromSlider(gadn)+1,FirstFromSlider(gadm)+1,FirstFromSlider(gaddelta));
  95.  
  96.         {wait until the user does some action, either closing the
  97.          window or playing with the sliders}    
  98.         msg:=WaitRequest(window);
  99.     UNTIL msg=CLOSEWINDOW_f;        
  100.  
  101.     {we don't need any request now. Actually, there's no need to
  102.      tell this windowlib explicitly since we shut down anyways...
  103.      At least it is good style}
  104.     RequestEnd(window,CLOSEWINDOW_f OR GADGETUP_f);
  105.  
  106.     {close the window}
  107.     CloseAWindow(window);
  108.  
  109.     ExitGraphics;        {shutdown gfx system}
  110. END.
  111.